package com.miao.hong.fang.course.service;

import java.sql.Timestamp;
import java.util.List;

import com.miao.hong.fang.IConstants;
import com.miao.hong.fang.course.dao.CourseDAO;
import com.miao.hong.fang.util.Utils;
import com.miao.hong.fang.util.pagination.ListAndCount;

public class CourseServiceImpl implements CourseService{

	private CourseDAO courseDAO;
	
	public CourseDAO getCourseDAO() {
		return courseDAO;
	}

	public void setCourseDAO(CourseDAO courseDAO) {
		this.courseDAO = courseDAO;
	}

	public List getAllCourseCategory() {
	
		return courseDAO.getAllCourseCategory();
	}
	
	public ListAndCount getPublicCourse(String year, String month, String location, String category) {
		
		if(month == null) {
			month = "01";
		}else if(month.length() < 2) {
			month = "0" + month;
		}
		String startDtAsStr = year + "-" + month + "-01";
		Timestamp startDt = Utils.stringToTimestamp(startDtAsStr, IConstants.COURSE_START_TIME_FORMAT);

		return courseDAO.getPublicCourse(startDt, location, category);
		
	}
	
	public List getAllCourseCities() {
		return courseDAO.getAllCourseCities();
	}
}
